package com.zrf.geekbang.spring.bean;

import com.zrf.geekbang.spring.bean.factory.InitializationUserFactory;
import com.zrf.geekbang.spring.bean.factory.UserFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * ben初始化demo
 * @author zhouruifeng
 * @date 2020-06-26
 */
public class BeanInitializationDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(BeanInitializationDemo.class);
        applicationContext.refresh();
        System.out.println("==========end=========");
        //非延迟初始化在应用上下文启动被初始化
        System.out.println(applicationContext.getBean(UserFactory.class));

        applicationContext.close();
    }

    @Bean(initMethod = "beanInitMethod", destroyMethod = "doDestory")
//    @Lazy
    public UserFactory userFactory() {
        return new InitializationUserFactory();
    }

}
